package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

/**
十进制转2进制
*/
func convertToBin(n int) string {
	result := ""
	for ; n > 0; n /= 2 {
		lsb := n % 2
		//strconv.Itoa()：转string
		result = strconv.Itoa(lsb) + result
	}

	return result
}

func printFile(filename string) {
	file, err := os.Open(filename)
	// 报错
	if err != nil {
		panic(err)
	}
	scanner := bufio.NewScanner(file)

	// 只有结束条件，相当于while，go语言没有while，通过for实现
	for scanner.Scan() {
		fmt.Println(scanner.Text())
	}
}

func forever() {
	// 死循环
	for {
		fmt.Println("abc")
	}

}

func main() {
	fmt.Println(convertToBin(5), //101
		convertToBin(13), //1101
		convertToBin(72387885),
		convertToBin(0),
	)

	printFile("abc.txt")
	//forever()
}
